package 早晨练习0314;

import java.util.*;
import java.util.stream.Collectors;

public class MorningPractice {
    /*
     * 1.利用接口判断一个点与圆的关系(内部,打印"在圆内部",上面:打印"在圆上",外面,打印:在圆外面"),
     * 1.1普通方法测试
     * 1.2使用匿名内部类测试(选做)
     * {@link ShapeContainer}
     */


    /*
     * 2.有一个字符串hello4422world23haha2bingbing54xiaokun33hello82788hello333333world67890xiaokun8838383838hello88877haha
     * 要求:
     *  1.将所有的单词找出,并确定每个单词的个数
     *  2.将单词和单词个数放入对象MyWord,将所有的MyWord对象存入数组.
     *  3.分别按照单词个数和单词从小到大排序(使用匿名内部类和lambda表达式(选做))
     */


    public static void main(String[] args) {
        //第一题
        ShapeContainer.Point center = new ShapeContainer.Point(3, 4);
        ShapeContainer.Circle circle = new ShapeContainer.Circle(center, 4);
        ShapeContainer.Point point = new ShapeContainer.Point(-1, -2);
        circle.print(point, (circle1, point1) -> circle1.getCenter().getDistanceOfPoint(point1) - circle1.getRadius());

        //第二题
        String str = "hello4422world23haha2bingbing54xiaokun33hello82788hello333333world67890xiaokun8838383838hello88877haha";
        String[] split = str.split("[0-9]+");
        Map<String, MyWord> map = new HashMap<>();
        for (String word : split) {
            if (!map.containsKey(word)) {
                MyWord temp = new MyWord(word, 1);
                map.put(word, temp);
            } else {
                MyWord myWord = map.get(word);
                myWord.setWordCount(myWord.getWordCount() + 1);
            }
        }
        List<MyWord> list = map.values().stream().sorted(Comparator.comparingInt(MyWord::getWordCount)
                .thenComparing(MyWord::getWord))
                .collect(Collectors.toList());
        System.out.println(list);
    }

}
